import type { Award, AwardRecord, AwardReview, ComprehensiveScore, Scholarship } from '@/types/scholarship'
import type { PageParams, PageResponse } from '@/utils/request'
import request from '@/utils/request'

/**
 * 奖学金评定规则相关
 */
// 获取学生填报的奖学金评定规则
export function getAwardList<T = Award, P = Record<string, any> & PageParams>(params?: P) {
  return request<T, PageResponse<T>>({
    url: '/system/awardType/list',
    method: 'get',
  })
}

// 获取所有奖学金评定规则
export function getAllAwardList<T = Award, P = Record<string, any> & PageParams>(params: P) {
  return request<T, PageResponse<T>>({
    url: '/system/awardType/list',
    params,
    method: 'get',
  })
}

// 根据id获取奖学金评定规则详情
export function getAwardInfo(applicationAwardTypeId: string | number) {
  return request({
    url: `/system/awardType/${applicationAwardTypeId}`,
    method: 'get',
  })
}

// 根据id修改奖学金评定规则详情
export function editAwardInfo(data: Award) {
  return request({
    url: `/system/awardType/edit`,
    method: 'post',
    data,
  })
}

// 根据id修改奖学金评定规则详情
export function addAwardInfo(data: Award) {
  return request({
    url: `/system/awardType/add`,
    method: 'post',
    data,
  })
}

// 根据id删除奖学金评定规则
export function deleteAwardInfo(applicationAwardTypeId: string | number) {
  return request({
    url: `/system/awardType/${applicationAwardTypeId}`,
    method: 'delete',
  })
}

/**
 * 学生奖学金申请相关
 */

// 查询个人申请列表
export function getApplications<T = Scholarship, P = Record<string, any> & PageParams>(params: P) {
  return request<T, PageResponse<T>>({
    url: '/system/applications/myList',
    params,
    method: 'get',
  })
}

// 获取审核历史记录
export function getApplication(applicationId: string | number) {
  return request<Scholarship>({
    url: `/system/applications/${applicationId}`,
    method: 'get',
  })
}

// 提交申请（暂存）
export function addApplication(data: Partial<Scholarship>) {
  return request<Scholarship>({
    url: '/system/applications/add',
    method: 'post',
    data,
  })
}

// 提交申请到审核
export function submitApplication(data: Partial<Scholarship>) {
  return request<Scholarship>({
    url: '/system/applications/reviewStart',
    method: 'post',
    data,
  })
}

// 获取审核人
export function addReviewers(params: Record<string, any>) {
  return request<{ userName: string; userId: string }, { userName: string; userId: string }[]>({
    url: '/system/applications/getClassReviewer',
    method: 'get',
    params,
  })
}

// 获取审核历史记录
export function getReviewList(params: { applicationId: string | number }) {
  return request<AwardReview, PageResponse<AwardReview>>({
    url: '/system/reviews/list',
    method: 'get',
    params,
  })
}

/**
 * 审核相关
 */
// 获取本人审核列表
export function getAuditsList<T = AwardReview, P = Record<string, any> & PageParams>(params: P) {
  return request<T, PageResponse<T>>({
    url: '/system/reviews/getReviews',
    method: 'get',
    params,
  })
}

export function getReviewersList(params: { roleKey: number }) {
  return request<{ userName: string; userId: string }, { userName: string; userId: string }[]>({
    url: '/system/applications/getxueyuanReviewer',
    method: 'get',
    params,
  })
}

export function doReviewer(data: Partial<AwardReview>) {
  return request({
    url: '/system/reviews/doReview',
    method: 'post',
    data,
  })
}

/**
 * 奖学金评定记录
 */

export function getAwardRecordList<T = AwardRecord, P = Record<string, any> & PageParams>(params: P) {
  return request<T, PageResponse<T>>({
    url: '/system/record/list',
    method: 'get',
    params,
  })
}

// 根据id修改奖学金评定规则详情
export function editAwardRecord(data: AwardRecord) {
  return request({
    url: `/system/record/edit`,
    method: 'post',
    data,
  })
}

// 根据id修改奖学金评定规则详情
export function addAwardRecord(data: AwardRecord) {
  return request({
    url: `/system/record/add`,
    method: 'post',
    data,
  })
}

// 根据id删除奖学金评定规则
export function deleteAwardRecord(awardId: string | number) {
  return request({
    url: `/system/record/${awardId}`,
    method: 'delete',
  })
}

/**
 * 综测管理
 */
// 综测列表
export function getComprehensiveScoreList<T = ComprehensiveScore, P = Record<string, any> & PageParams>(params: P) {
  return request<T, PageResponse<T>>({
    url: '/system/comprehensiveScore/list',
    method: 'get',
    params,
  })
}

// 综测列表
export function getComprehensiveScoreListById<T = ComprehensiveScore>(id: string | number) {
  return request<T>({
    url: `/system/comprehensiveScore/${id}`,
    method: 'get',
  })
}

// 综测修改
export function editComprehensiveScore(data: ComprehensiveScore) {
  return request({
    url: `/system/comprehensiveScore/edit`,
    method: 'post',
    data,
  })
}

// 综测新增
export function addComprehensiveScore(data: ComprehensiveScore) {
  return request({
    url: `/system/comprehensiveScore/add`,
    method: 'post',
    data,
  })
}

// 综测删除
export function deleteComprehensiveScore(comprehensiveScoreId: string | number) {
  return request({
    url: `/system/comprehensiveScore/${comprehensiveScoreId}`,
    method: 'delete',
  })
}
